﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZHDJ.Core.Caching;
using ZHDJ.Data.Models.Common;

namespace ZHDJ.Data.DataCaching
{
    /// <summary>
    /// 页面模块（左边菜单）
    /// </summary>
    public class PartyModuleNavigationCaching
    {
        private MemoryCacheManager Cache;
        private List<PartyModuleNavigation> _Queryable;

        public PartyModuleNavigationCaching()
        {
            Cache = new MemoryCacheManager();
        }

        public List<PartyModuleNavigation> Queryable
        {
            get
            {
                _Queryable = Cache.Get(CacheKeys.Cache_PartyModuleNavigation, () =>
                {
                    using (var db = new DBInstance().DB)
                    {
                        return db.PartyModuleNavigations.OrderBy(a=>a.OrderNo).ToList();
                    }
                });

                return _Queryable;

            }
        }

        /// <summary>
        /// 获取模块
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static List<PartyModuleNavigation> Get(string module)
        {
            PartyModuleNavigationCaching cah = new PartyModuleNavigationCaching();
            return cah.Queryable.Where(a => a.Module == module).ToList();
        }


        /// <summary>
        /// 清除
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static void Clean()
        {
            PartyModuleNavigationCaching cah = new PartyModuleNavigationCaching();
            cah.Cache.Remove(CacheKeys.Cache_PartyModuleNavigation);
        }
    }
}
